package com.pro.controller;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Service;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import sun.net.www.content.text.plain;

import com.pro.beans.Alarm;
import com.pro.beans.Page;
import com.pro.beans.Person;
import com.pro.beans.Polling;
import com.pro.mybatis.ListPage;
import com.pro.mybatis.MyBatisExpression;
import com.pro.mybatis.SearchCondition;
import com.pro.param.RequestParam;
import com.pro.param.ResponseParam;
import com.pro.service.PollingService;

@Controller
public class PollerController extends BaseController{

	@Resource
	public PollingService pollingService;
	
	@RequestMapping("loadPollingList.json")
	@ResponseBody
	public ResponseParam<Alarm> loadPollingList(@ModelAttribute("Page")Page page,@ModelAttribute("requestParam")RequestParam requestParam){
		ListPage listPage = pollingService.loadPollingList(requestParam);
		List<Person> personList = pollingService.personList();
		this.setData(listPage);
		this.setDataList(personList);
		this.setSuccess(true);
		return this.getResponseParam();
	}
	
	@RequestMapping("loadPollingById.json")
	@ResponseBody
	public ResponseParam<Polling> loadPollingById(@org.springframework.web.bind.annotation.RequestParam("id")Integer id){
		Polling polling = pollingService.getPollingById(id);
		this.setData(polling);
		this.setSuccess(true);
		return this.getResponseParam();
	}
	
	@RequestMapping("loadPolling.do")
	public String loadPollingList(@org.springframework.web.bind.annotation.RequestParam("id")Integer id,Model model){
		if(id==null || id.equals("")){
			model.addAttribute("msg","请选中一项");
			model.addAttribute("jspName", "polling");
		}else{
			Polling polling = pollingService.getPollingById(id);
			model.addAttribute("polling", polling);
			model.addAttribute("jspName", "addPolling");
		}
//		${topName}>${urlName}
		model.addAttribute("topName", "巡检任务"
				+ "");
		model.addAttribute("urlName", "添加巡检");
		this.setSuccess(true);
//		this.setMsg("添加成功!");
		model.addAttribute("menuId", "2");
		return "index";
	}
	public ResponseParam<Person> loadAllPerson(){
		
		return this.getResponseParam();
	}
	
	@RequestMapping("addPolling.do")
	public String loadPollingList(@ModelAttribute("polling")Polling polling,Model model){
		if(polling.getId()!=null){
			pollingService.updatePolling(polling);
		}else{
			pollingService.addPolling(polling);
		}
		this.setSuccess(true);
		this.setMsg("添加成功!");
		model.addAttribute("msg", "操作成功");
		model.addAttribute("jspName", "polling");
		model.addAttribute("menuId", "2");
		return "index";
	}

	@RequestMapping("assignPerson.do")
	public String assignPerson(@ModelAttribute("polling")Polling polling,Model model){
		pollingService.updatePolling(polling);
		this.setSuccess(true);
		model.addAttribute("msg", "操作成功");
		model.addAttribute("jspName", "polling");
		model.addAttribute("menuId", "2");
		return "index";
	}
}
